package com.fxpc.util;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;

public class DateUtil {

    /**
     * 获取yyyyMMdd HH:mm:ss
     *
     * @param date
     * @return
     */
    public static String getContainsHMS(Date date) {
        if (date != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
            String format = sdf.format(date);
            return format;
        } else {
            return "时间不能为空";
        }
    }

    /**
     * 获取yyyyMMdd
     *
     * @param date
     * @return
     */
    public static String getNotContainsHMS(Date date) {
        if (date != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String format = sdf.format(date);
            return format;
        } else {
            return "时间不能为空";
        }
    }

    public static HashMap<String, String> getTime() {

        String startformat = LocalDateTime.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        String endformat = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        /*String startformat=  LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        String  endformat = LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));*/
        //当天时间
        StringBuilder start = new StringBuilder();
        start.append(startformat).append(" 00:00:00");
        //前一天时间
        StringBuilder end = new StringBuilder();
        //String endformat = sdf.format(lastDay);
        end.append(endformat).append(" 00:00:00");

        HashMap<String, String> hashMap = new HashMap();
        hashMap.put("start", start.toString());
        hashMap.put("end", end.toString());
        return hashMap;
    }
}
